package com.usefullc.english.service;

import com.usefullc.common.util.BeanUtils;
import com.usefullc.english.domain.Subtitle;
import com.usefullc.english.domain.Tag;
import com.usefullc.english.domain.UserSubtitle;
import com.usefullc.english.enums.ContentStatusEnum;
import com.usefullc.english.query.*;
import com.usefullc.english.vo.ContentVo;
import com.usefullc.common.enums.YesNoEnum;
import com.usefullc.english.vo.SubtitleVo;
import com.usefullc.english.vo.UserSubtitleVo;
import com.usefullc.system.service.component.extend.ExtendDataComponent;
import com.usefullc.system.vo.TreeVo;
import com.usefullc.user.service.component.UserManager;
import com.usefullc.user.vo.UserVo;
import org.apache.commons.collections.CollectionUtils;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author: Sampson
 * @date: 2022-07-08 10:17
 */
@Service("englishService")
public class EnglishService {

    @Autowired
    private CategoryService categoryService;

    @Autowired
    private ContentService contentService;

    @Autowired
    private TagService tagService;

    @Autowired
    private SubtitleService subtitleService;

    @Autowired
    private UserSubtitleService userSubtitleService;

    @Autowired
    private ExtendDataComponent extendDataComponent;

    public List<TreeVo> listTree(){
        List<TreeVo> treeVoList = categoryService.listTree(new CategoryQuery());
//        List<Category> categoryList = categoryService.findAll(new CategoryQuery());
//        Map<Long, Category> categoryMap = categoryList.stream().collect(Collectors.toMap(data -> data.getId(), data -> data));
//        Map<Long, List<Category>> parentCategoryMap = categoryList.stream().collect(Collectors.groupingBy(Category::getParentId));
//        List<NavTreeVo> navTreeVoList = new ArrayList<>();
//        for (TreeVo treeVo : treeVoList) {
//            NavTreeVo navTreeVo = new NavTreeVo();
//            navTreeVoList.add(navTreeVo);
//            String key = treeVo.getKey();
//            Long categoryId = Long.valueOf(key);
//            Category category = categoryMap.get(categoryId);
//            navTreeVo.setUrl(category.getUrl());
//
//
//            List<Category> children = parentCategoryMap.get(categoryId);
//
//        }
        return treeVoList;


    }

    public List<ContentVo> recommendList(){
        ContentQuery contentQuery = new ContentQuery();
        contentQuery.setStatus(ContentStatusEnum.RELEASED.getCode());
        contentQuery.setRecommend(YesNoEnum.YES.getCode());
        List<ContentVo> recommendList = contentService.findCmsList(contentQuery);
        return recommendList;
    }

    public List<ContentVo> readList(){
        ContentQuery contentQuery = new ContentQuery();
        contentQuery.setStatus(ContentStatusEnum.RELEASED.getCode());
        contentQuery.setOrderByColumn("readNum");
        contentQuery.setAscOrDesc("desc");
        contentQuery.setResultLimit(10);
        List<ContentVo> recommendList = contentService.findCmsList(contentQuery);
        return recommendList;
    }


    public List<ContentVo> newList(){
        ContentQuery contentQuery = new ContentQuery();
        contentQuery.setStatus(ContentStatusEnum.RELEASED.getCode());
        contentQuery.setOrderByColumn("top,gmtRelease");
        contentQuery.setAscOrDesc("desc");
        contentQuery.setResultLimit(10);
        List<ContentVo> newList = contentService.findCmsList(contentQuery);
        return newList;
    }


    public List<ContentVo> categoryContentList(Long categoryId){
        ContentQuery contentQuery = new ContentQuery();
        contentQuery.setCategoryId(categoryId);
        contentQuery.setStatus(ContentStatusEnum.RELEASED.getCode());
        contentQuery.setOrderByColumn("orderNo");
        contentQuery.setAscOrDesc("asc");
        List<ContentVo> newList = contentService.findCmsList(contentQuery);
        return newList;
    }




    public List<Tag> tagList(){
        TagQuery query = new TagQuery();
        query.setResultLimit(10);  //后续根据文章数量或者文章热度
        List<Tag> dataList = this.tagService.findAll(query);
        return dataList;
    }
}
